package org.example.utils;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.example.config.MybatisPlusConfig;

/**
 * MyBatis工具类
 */
public class MybatisUtil {
    private static final SqlSessionFactory sqlSessionFactory = MybatisPlusConfig.getSqlSessionFactory();

    /**
     * 获取SqlSession
     */
    public static SqlSession getSqlSession() {
        return sqlSessionFactory.openSession(true); // 自动提交事务
    }

    /**
     * 获取Mapper
     */
    public static <T> T getMapper(Class<T> mapperClass) {
        return getSqlSession().getMapper(mapperClass);
    }
} 